from __future__ import annotations

import json
from pathlib import Path
from typing import Any, Dict

from .models import GenerationOutput


def export_to_json(output: GenerationOutput, path: str) -> str:
    target = Path(path)
    target.parent.mkdir(parents=True, exist_ok=True)
    with target.open("w", encoding="utf-8") as f:
        json.dump(output.to_dict(), f, ensure_ascii=False, indent=2)
    return str(target)